package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Organization;
import cn.wolfcode.crm.query.OrganizationQuery;
import cn.wolfcode.crm.service.IOrganizationService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("organization")
public class OrganizationController {
    @Autowired
    private IOrganizationService organizationService;

    //视图
    @RequestMapping("/view")
    public String index() {
        return "information/organization";
    }


    //查询所有
    @RequestMapping("/selectAll")
    @ResponseBody
    public Object selectAll() {
        return organizationService.listAll();
    }
    
    @RequestMapping("/query")
    @ResponseBody
    public Object query(OrganizationQuery qo){
        return organizationService.query(qo);
    }

    //新增/编辑
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Organization entity) {
        try {
            organizationService.saveOrUpdate(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new JsonResult().mark(ex.getMessage());
        }
        return new JsonResult();
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        organizationService.delete(id);
        return new JsonResult();
    }

    @RequestMapping("/changeCooperation")
    @ResponseBody
    public Object changeCooperation(Long id){
        try {
            organizationService.changeCooperation(id);
        } catch (Exception ex) {
            return new JsonResult().mark(ex.getMessage());
        }
        return new JsonResult();
    }

    @RequestMapping("selectOrganizationInfo")
    @ResponseBody
    public Object selectOrganizationInfo(){
        return organizationService.selectOrganizationInfo();
    }
}
